﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SN.Models;
using System.Collections;
namespace SN.Report
{
    public partial class BatchInputFormulaDlg : Form
    {
        public FormTemp FrmTemp;
        public  string zbbh = "";
        public  int iSheet ;

        public BatchInputFormulaDlg()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string lsFormula = this.richTextBox1.Text.Trim();
            //判断字符长度不能超过1000
            if (lsFormula.Length > 1000)
            {
                MessageBox.Show("公式太长啦!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //首先判断该表达式是否有效
            if (this.richTextBox1.Text.IndexOf(zbbh) >= 0)
            {
                MessageBox.Show("指标公式不合法，存在循环引用!");
                return;
            }
          
            //写开始行 与开始列 （即指标公式所在的行与列)
            FrmTemp.cellControl1.axCell.SetCellTip(FrmTemp.startCol, FrmTemp.startRow, iSheet, this.richTextBox1.Text);
            Close();
        }

        private void BatchInputFormulaDlg_Load(object sender, EventArgs e)
        {
            
            iSheet = FrmTemp.cellControl1.axCell.GetCurSheet();

            zbbh = FrmTemp.cellControl1.axCell.GetCellString(FrmTemp.startCol, FrmTemp.startRow, iSheet);

            if (string.IsNullOrEmpty(zbbh)) zbbh = "";

            this.Text = zbbh + this.Text;
            this.richTextBox1.Text = FrmTemp.cellControl1.axCell.GetCellTip(FrmTemp.startCol, FrmTemp.startRow, iSheet)!=null?FrmTemp.cellControl1.axCell.GetCellTip(FrmTemp.startCol, FrmTemp.startRow, iSheet):""; //指标计算表达式
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (this.richTextBox1.Text.Trim().Length == 0) return;

            ArrayList aExpriss = new ArrayList();
            //计算表达式
            object o = SN.Services.Expression.ComputeExpression(this.richTextBox1.Text);

            MessageBox.Show(o.ToString());

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "+";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "-";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "*";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Text += "/";
        }
    }
}
